﻿package conn;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
 * 数据库连接工具类
 * @author Administrator
 *
 */
public class ConnectDatabase {
	
	private static final String DRIVER_STRING="com.mysql.jdbc.Driver";
	private static final String URL_STRING= "jdbc:mysql://localhost:3306/mypet?useUnicode=true&characterEncoding=gbk";
	private static final String USER_STRING="root";
	private static final String PASS_STRING="";
	
	public static Connection getConnection(){
		Connection connection=null;
		
		try {
			Class.forName(DRIVER_STRING);
			connection=DriverManager.getConnection(URL_STRING, USER_STRING, PASS_STRING);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return connection;
	}
	public void realse(Connection conn,PreparedStatement ps,ResultSet rs){
		if(conn!=null){
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if(ps!=null){
			try {
				ps.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if(rs!=null){
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
}
